<template>
  <div class="sales-division">
    <router-view v-if="route.matched.length === 3" />
    <e-container v-else class="container">
      <a-spin :spinning="loading" tip="Loading...">
        <a-table
          :columns="columns"
          :data-source="data"
          class="ant-table-striped"
          :pagination="false"
          :row-class-name="(_record, index) => (index % 2 === 0 ? 'table-striped' : null)"
        >
          <template #bodyCell="{ column, record }">
            <template v-if="column.key === 'paymentNum'">
              <a @click="clickBatchNumber(record)">{{ record.paymentNum }}</a>
            </template>
          </template>
          <template #emptyText>
            <e-empty>
              <template #description>
                <div>No Data</div>
              </template>
            </e-empty>
          </template>
        </a-table>
      </a-spin>
    </e-container>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import EContainer from '@/components/EContainer.vue'
import EEmpty from '@/components/EEmpty.vue'
import pageColumns from '@/assets/script/page_columns.js'
import p from '@/api/performance.js'

const salesDivision = pageColumns.salesDivision
const columns = reactive(salesDivision)
const data = ref([])
const route = useRoute()
const router = useRouter()
const loading = ref(false)
/**
 * 点击跳转
 */
const clickBatchNumber = record => {
  router.push({
    path: route.path + '/commission',
    query: {
      paymentNum: record.paymentNum
    }
  })
}
/**
 * 获取列表数据
 */
const getList = () => {
  loading.value = true
  p.getSalesDivision()
    .then(res => {
      if (res.code === 2000) {
        data.value = res.data
      }
    })
    .finally(() => {
      setTimeout(() => {
        loading.value = false
      }, 30)
    })
}
onMounted(() => {
  getList()
})
</script>

<style scoped lang="less">
@import '@/assets/style/reset_table';
</style>
<route lang="yaml">
name: Sales Division
path: '/sales-division/'
meta:
  title: Sales Division
  roles: isPrimaryCSO, isBranchCSO
</route>
